import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/OnePage.dart';
import 'package:flutter_app/TwoPage.dart';
import 'package:flutter_app/ThreePage.dart';
import 'package:flutter_app/FourPage.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: "TabBar 测试",
      theme: ThemeData(primarySwatch: Colors.blue),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageSate createState() => _MyHomePageSate();
}

class _MyHomePageSate extends State<MyHomePage> {
  int _selectIndex = 0;

  final List tabBodies = [OnePage(), TwoPage(), ThreePage(), FourPage()];
  var currentPage;

  @override
  Widget build(BuildContext context) {
    print('build context...');
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('tabbar'),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            title: Text(
              '按钮事件',
            ),
            icon: Icon(
              CupertinoIcons.home,
              color: Colors.black,
            ),
            activeIcon: Icon(
              CupertinoIcons.home,
              color: Colors.green,
            ),
          ),
          BottomNavigationBarItem(
            title: Text(
              '布局',
            ),
            icon: Icon(
              CupertinoIcons.phone,
              color: Colors.black,
            ),
            activeIcon: Icon(
              CupertinoIcons.phone,
              color: Colors.green,
            ),
          ),
          BottomNavigationBarItem(
            title: Text(
              '插件',
            ),
            icon: Icon(
              CupertinoIcons.mail,
              color: Colors.black,
            ),
            activeIcon: Icon(
              CupertinoIcons.mail,
              color: Colors.green,
            ),
          ),
          BottomNavigationBarItem(
            title: Text(
              'HTTP',
            ),
            icon: Icon(
              CupertinoIcons.profile_circled,
              color: Colors.black,
            ),
            activeIcon: Icon(
              CupertinoIcons.profile_circled,
              color: Colors.green,
            ),
          ),
        ],
        iconSize: 24,
        currentIndex: _selectIndex,
        onTap: (index) {
          setState(() {
            _selectIndex = index;
            currentPage = tabBodies[_selectIndex];
          });
        },
        fixedColor: Colors.green,
        type: BottomNavigationBarType.fixed,
      ),
      body: currentPage,
    );
  }
}
